import random
import cv2
import numpy as np

img_path = "./mask_img/0520_9660.jpg"


def automaticpolygon():
    """功能：语义分割模型检测，自动识别画框"""
    automatic_pionts = []
    img = cv2.imread(img_path)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    cv2.threshold(img, 110, 0, cv2.THRESH_TOZERO_INV, img)
    cv2.threshold(img, 110 - 1, 255, cv2.THRESH_BINARY, img)
    contours, hierarchy = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    cv2.imshow("img", img)
    cv2.waitKey(0)
    for i in contours:
        for j in i:
            for k in j:
                automatic_pionts.append(list(k))
    print(automatic_pionts)


if __name__ == "__main__":
    # showskt(im, anns)
    automaticpolygon()
